package com.xingzhe.content.api;

import com.xingzhe.content.mapper.TeachplanMapper;
import com.xingzhe.content.model.dto.BindTeachplanMediaDto;
import com.xingzhe.content.model.dto.SaveTeachPlanDto;
import com.xingzhe.content.model.dto.TeachplanDto;
import com.xingzhe.content.model.po.Teachplan;
import com.xingzhe.content.service.TeachPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 课程计划管理的相关接口
 */
@Api(value = "课程计划管理接口",tags = "课程计划管理接口")
@RestController
public class TeachplanController {

    @Resource
    private TeachPlanService teachPlanService;

    @Resource
    private TeachplanMapper teachplanMapper;

    @ApiOperation("查询课程计划树形结构")
    @ApiImplicitParam(value = "courseId", name = "课程Id", required = true, dataType = "Long", paramType = "path")
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId) {
        return teachPlanService.findTeachPlanTree(courseId);
    }

    @ApiOperation("课程计划的创建或者修改")
    @PostMapping("/teachplan")
    public void saveTeachplan(@RequestBody SaveTeachPlanDto teachplan) {
        teachPlanService.saveTeachPlan(teachplan);
    }

    @ApiOperation("课程计划的删除")
    @DeleteMapping("/teachplan/{teachPlanId}")
    public void deleteTeachPlan(@PathVariable(value = "teachPlanId") Long teachPlanId) {
        teachPlanService.deleteTeachPlan(teachPlanId);
    }

    ///teachplan/movedown/268
    @ApiOperation("课程计划的向下移动")
    @PostMapping("/teachplan/movedown/{teachPlanId}")
    public List<TeachplanDto> moveDown(@PathVariable(value = "teachPlanId") Long teachPlanId) {
        return teachPlanService.moveDownTeachPlan(teachPlanId);
    }

    ///teachplan/moveup/268
    @ApiOperation("课程计划的向上移动")
    @PostMapping("/teachplan/moveup/{teachPlanId}")
    public List<TeachplanDto> moveUp(@PathVariable(value = "teachPlanId") Long teachPlanId) {
        return teachPlanService.moveUpTeachPlan(teachPlanId);
    }


    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto) {
        teachPlanService.associationMedia(bindTeachplanMediaDto);
    }

    @ApiOperation(value = "课程计划和媒资信息解绑")
    @DeleteMapping("/teachplan/association/media/{teachPlanId}/{mediaId}")
    public void NotAssociationMedia(@PathVariable("teachPlanId")Long teachPlanId,
                                    @PathVariable("mediaId")String mediaId){
        teachPlanService.NotAssociationMedia(teachPlanId, mediaId);

    }

    @ApiOperation("供学习中心服务调用的查询课程计划信息")
    @GetMapping("/teachplan/getOne/{teachplanId}")
    public Teachplan getOne(@PathVariable("teachplanId") Long teachplanId){
        return teachplanMapper.selectById(teachplanId);
    }


}
